package com.example.testapp.activity.fragment;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatImageView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.example.testapp.R;
import com.example.testapp.activity.activity.study.StudyActivity;
import com.example.testapp.activity.activity.meact.WebActivity;
import com.example.testapp.activity.activity.meact.PictureActivity;

/**
 * Created by l on 2016/7/2.
 */
public class MeFragment extends BaseFragment {

    private static final String ARG_PARAM1 = "param1";
    private static final String PICTURE_ITEM = "picture_item";
    private  String mParam1;
    private  float  mValue;
    private ProgressDialog mDialog;
    private LinearLayout mImageLayout = null;
    private LinearLayout mPictureLayout = null;
    private LinearLayout mWebLayout = null;
    private LinearLayout mLearnLayout = null;
    private AppCompatImageView  mComatImage = null;

    public MeFragment(){ }

    public MeFragment newInstance(String param) {
        MeFragment fragment = new MeFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(getArguments() != null){
            mParam1 = getArguments().getString(ARG_PARAM1);
        }
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_me, container, false);

        initData();
        initView(view);
        return view;
    }

    private void initData() {
       mDialog = new ProgressDialog(getActivity());
       mDialog.setMessage("加载中......");
       mDialog.setCancelable(true);
       mDialog.setCanceledOnTouchOutside(false);
       mDialog.show();
       new Thread(new Runnable() {
           @Override
           public void run() {
               try {
                   Thread.sleep(3000);
                   mDialog.dismiss();
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
       }).start();
    }

    private void initView(View view) {
        mComatImage = (AppCompatImageView)view.findViewById(R.id.compatimage);
        mImageLayout = (LinearLayout)view.findViewById(R.id.ImageLayout);
        mPictureLayout = (LinearLayout)view.findViewById(R.id.pictureLayout);
        mWebLayout = (LinearLayout)view.findViewById(R.id.webLayout);
        mLearnLayout = (LinearLayout)view.findViewById(R.id.learnsLayout);

        initListener();
    }

    private void initListener() {
        mImageLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        mPictureLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent  intent = new Intent();
                intent.putExtra("picture_item", PICTURE_ITEM);
                intent.setClass(getActivity(),  PictureActivity.class);
                startActivity(intent);
            }
        });

        mWebLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), WebActivity.class);

                startActivity(intent);
            }
        });

        mLearnLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), StudyActivity.class);

                startActivity(intent);
            }
        });
    }
}
